package com.mobiletrain.org.motherkitch.sliding.caipu;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/4/28.
 */
public class MyCaipuAdapter extends BaseAdapter {

    private Context context;
    private List<Caipu> datas;
    private LayoutInflater layoutInflater;

    public MyCaipuAdapter(Context context, List<Caipu> datas) {
        this.context = context;
        this.datas = datas;
        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        if (datas != null) {
            return datas.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {

        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CaipuHolder holder = null;
        if (convertView == null) {
            holder = new CaipuHolder();
            convertView = layoutInflater.inflate(android.R.layout.simple_list_item_2, null);
            holder.name = (TextView) convertView.findViewById(android.R.id.text1);
            holder.shortmsg = (TextView) convertView.findViewById(android.R.id.text2);
            convertView.setTag(holder);
        } else {
            holder = (CaipuHolder) convertView.getTag();
        }

        Caipu caipu = datas.get(position);
        holder.name.setText(caipu.getName());
        holder.shortmsg.setText(caipu.getSmsg());

        return convertView;
    }

    class CaipuHolder {
        TextView name;
        TextView shortmsg;
    }
}
